package AdminController;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import Ara_Bean.NboardBean;
import Ara_Bean.RboardBean;
import Ara_Dao.RboardDao;

import com.ibatis.sqlmap.client.SqlMapException;

public class NboardCmInsert  extends AbstractCommandController{
	
	private RboardDao rboardDao;
	
	public void setRboardDao(RboardDao rboardDao) {
		this.rboardDao = rboardDao;
	}
	
	@Override
	protected ModelAndView handle(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, BindException arg3)
			throws Exception {
		// TODO Auto-generated method stub
		NboardBean nboardbean = (NboardBean)arg2;
	
		try {
			rboardDao.NboardcmInsert(nboardbean);
			
			System.out.println(nboardbean);
			System.out.println("리플 입력성공");
			
		} catch (SqlMapException e) {
			e.printStackTrace();
			System.out.println("리플 입력실패");
		}
		
		Object nboard = rboardDao.NboardDetail(arg0.getParameter("nb_no"));		
		List<?> ripple = rboardDao.NboardcmDetail(arg0.getParameter("ripple_subid"));
				
		ModelAndView mav = new ModelAndView();
		
		mav.addObject("rboard",nboard);
		mav.addObject("rippledetail",ripple);
		mav.setViewName("BoardDetail");
		
		return mav;
	}

}

